﻿package com.dg.gaming.client{
	import com.dg.gaming.api.common.msg.MsgConnectTable;

	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.Socket;

	import nanoxml.XMLElement;

	/**
	 * ...
	 * @author ...
	 */
	public class TestClient implements IClient {
		private var socket:Socket;

		public function TestClient() {
			socket=new Socket("localhost",1790);
			socket.addEventListener(Event.CONNECT,connectedHandler);
			socket.addEventListener(IOErrorEvent.IO_ERROR,onIOError);

		}
		private function onIOError(evt:IOErrorEvent):void {
			trace(evt.text);
		}
		private function connectedHandler(event:Event):void {
			var conn:TableConnection=new TableConnection(socket,1,this);
			var msg:MsgConnectTable=new MsgConnectTable(1,1,1);
			conn.send(msg);
		}

		/* INTERFACE com.dg.gaming.client.IClient */

		public function receiveGameMessage(message:XMLElement):void {
			trace(message.toString());
		}

		public function receiveTableMessage(message:XMLElement,tableNum:String):void {
			trace(message.toString()+tableNum);
		}

	}

}